#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char *gcdOfStrings(char *str1, char *str2)
{
    int n1 = strlen(str1), n2 = strlen(str2);
    while (1) {
        if (n1 == n2 && strncmp(str1, str2, n1) == 0) {
            return str1;
        } else if (n1 > n2 && strncmp(str1, str2, n2) == 0) {
            str1 += n2, n1 -= n2;
        } else if (n1 < n2 && strncmp(str1, str2, n1) == 0) {
            str2 += n1, n2 -= n1;
        } else {
            return "";
        }
    }
}

void testgcdOfStrings(const char *test_name, const char *str1, const char *str2, const char *expected_result)
{
    const char *result = gcdOfStrings((char *)str1, (char *)str2);
    if (strcmp(result, expected_result) == 0) {
        printf("%s passed.\n", test_name);
    } else {
        printf("%s failed. Expected: %s, Actual: %s\n", test_name, expected_result, result);
    }
}

int main()
{
    testgcdOfStrings("Test Case 1", "ABCABC", "ABC", "ABC");
    testgcdOfStrings("Test Case 2", "ABABAB", "ABAB", "AB");
    testgcdOfStrings("Test Case 3", "LEET", "CODE", "");
}